package com.bdqn.tour.servlet.Hzy;

import com.alibaba.fastjson.JSONObject;
import com.bdqn.tour.pojo.HzyLocation;
import com.bdqn.tour.service.HzyLocationService;
import com.bdqn.tour.service.impl.HzyLocationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/editLocation")
public class GetLocationIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");

        //获取参数
        String strId = req.getParameter("id");

            if (strId != null && !strId.isEmpty()) {
                int id = Integer.parseInt(strId);
                HzyLocationService locationService = new HzyLocationServiceImpl();
                HzyLocation location = locationService.getLocationById(id);


                if (location != null) {
                    String json = JSONObject.toJSONString(location);
                    resp.getWriter().write(json);
                }
            }
    }
}
